package com.sxt.sys.controller;


import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import com.sxt.springcloud.sys.RoleClientService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sxt.sys.common.Constast;
import com.sxt.sys.common.DataGridView;
import com.sxt.sys.common.ResultObj;
import com.sxt.sys.common.TreeNode;
import com.sxt.sys.domain.Permission;
import com.sxt.sys.domain.Role;
import com.sxt.sys.vo.RoleVo;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 老雷
 * @since 2019-09-24
 */
@RestController
@RequestMapping("/role")
public class RoleController {

	@Autowired
	private RoleClientService roleService;

	
	
	/**
	 * 查询
	 */
	@RequestMapping("loadAllRole")
	public DataGridView loadAllRole( RoleVo roleVo) {
		return this.roleService.loadAllRole(roleVo);
	}
	
	
	/**
	 * 添加
	 */
	@RequestMapping("addRole")
	public ResultObj addRole( RoleVo roleVo) {
		return this.roleService.addRole(roleVo);
	}
	/**
	 * 修改
	 */
	@RequestMapping("updateRole")
	public ResultObj updateRole( RoleVo roleVo) {
		return this.roleService.updateRole(roleVo);
	}
	
	/**
	 * 删除
	 */
	@RequestMapping("deleteRole")
	public ResultObj deleteRole(@RequestParam("id") Integer id) {
		return this.roleService.deleteRole(id);
	}
	
	
	/**
	 * 根据角色ID加载菜单和权限的树的json串
	 */
	@RequestMapping("initPermissionByRoleId")
	public DataGridView initPermissionByRoleId(@RequestParam("roleId") Integer roleId) {
		return this.roleService.initPermissionByRoleId(roleId);
	}
	
	/**
	 * 保存角色和菜单权限之间的关系
	 */
	@RequestMapping("saveRolePermission")
	public ResultObj saveRolePermission(@RequestParam("rid") Integer rid,@RequestParam("ids") Integer[] ids) {
		return this.roleService.saveRolePermission(rid,ids);
	}
}

